#include <QDebug>
#include <QCoreApplication>
#include "hybridwebpage.h"

#if defined(Q_OS_SYMBIAN) && defined(WINSCW)
#define EMULATOR
#endif

HybridWebPage::HybridWebPage(QObject *parent)
	: QWebPage(parent)
{
#if QT_VERSION >= 0x040600
    settings()->setAttribute(QWebSettings::LocalContentCanAccessRemoteUrls, true);
#endif
}

void HybridWebPage::javaScriptConsoleMessage(const QString& message,
		int lineNumber, const QString& sourceID)
{
    QString consoleMessage = tr("[JS] message: %1 lineNumber: %2 sourceID: %3").arg(
                    message).arg(lineNumber).arg(sourceID);
    
    qDebug() << consoleMessage;
    
    if(m_logFile.isOpen())
    {
    	QTextStream log(&m_logFile);
    	log << consoleMessage;
    }
}

void HybridWebPage::enableLogging()
{
	if(!m_logFile.isOpen())
	{
		m_logFile.setFileName("c:\\data\\hag_console.log");
		if(!m_logFile.open(QIODevice::Append | QIODevice::Text))
			return;
	}
}
